import Vue from 'vue'
import Router from 'vue-router'
const index = resolve => require(['@/pages/index/index'], resolve);
const home = resolve => require(['@/pages/index/home'], resolve);

const personal = resolve => require(['@/pages/personal/personal'], resolve);

const admin = resolve => require(['@/pages/admin/admin'], resolve);
const seat = resolve => require(['@/pages/admin/seat'], resolve);
const bmks = resolve => require(['@/pages/admin/bmks'], resolve);

const test = resolve => require(['@/pages/test/test'], resolve);


Vue.use(Router)

const VueRouterPush = Router.prototype.push
Router.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

export default new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      component: index,
      redirect: 'home',
      children: [
        {
          path: '/home',
          name: 'home',
          component: home,
        },
        {
          path: '/personal',
          name: 'personal',
          component: personal,
          beforeEnter: (to, from, next) => {
            if ($cookies.get('__tk')) {
              next()
            } else {
              next('/')
              // console.log('请先登录')
            }
          }
        },
        {
          path: '/admin',
          name: 'admin',
          component: admin,
          beforeEnter: (to, from, next) => {
            if ($cookies.get('__tk')) {
              if($cookies.get('__ac') && $cookies.get('__ac') != 401){
                next();
              }else{
                next('/')
                // console.log('没有权限')
              }
            } else {
              next('/')
              // console.log('请先登录')
            }
          }
        },
        {
          path: '/seat',
          name: 'seat',
          component: seat,
          beforeEnter: (to, from, next) => {
            if ($cookies.get('__tk')) {
              if($cookies.get('__ac') && $cookies.get('__ac') != 401){
                next();
              }else{
                next('/')
                // console.log('没有权限')
              }
            } else {
              next('/')
              // console.log('请先登录')
            }
          }
        },
        {
          path: '/bmks',
          name: 'bmks',
          component: bmks,
          beforeEnter: (to, from, next) => {
            if ($cookies.get('__tk')) {
              if($cookies.get('__ac') && $cookies.get('__ac') != 401){
                next();
              }else{
                next('/')
                // console.log('没有权限')
              }
            } else {
              next('/')
              // console.log('请先登录')
            }
          }
        },
      ]
    },
    // {
    //   path: '/test',
    //   name: 'test',
    //   component: test,
    // }
  ]
})
